package cn.bookshare.comment.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.bookshare.comment.vo.Comment;
import cn.bookshare.user.vo.User;

/**
 * 评论模块持久层代码
 * @author Lijt
 * @version 2017-2-23 下午2:47:42
 */
public class CommentDao extends HibernateDaoSupport{
	
	// 添加评论存入数据库
	public void save(Comment comment) {
		this.getHibernateTemplate().save(comment);
	}
	
	//删除评论
	public void delete(Comment comment) {
		this.getHibernateTemplate().delete(comment);
	}
	
	//修改评论审核状态
	public void updateCommentFlag(Comment comment) {
		this.getHibernateTemplate().update(comment);
	}
	
	/*
	 * search模块
	 */
	// 根据图书id查询评论
	public List<Comment> findByBid(Integer bid) {
		String hql = "from User where bid = ?";
		List<Comment> list = this.getHibernateTemplate().find(hql, bid);
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}
	
	// 根据评论用户昵称查询评论
	public List<Comment> findByUserName(String userName) {
		String hql = "from User where username = ?";
		List<Comment> list = this.getHibernateTemplate().find(hql, userName);
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}
}
